package com.stylefeng.guns.modular.capitalBudget.model;

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import cn.afterturn.easypoi.util.PoiPublicUtil;

import java.util.Map;

/**
 *资金预算xecel表解析标题匹配
 * @author laoyu
 * @date 2018-07-24
 */
public class CapitalBudgetImportHandler extends ExcelDataHandlerDefaultImpl<Map<String,Object>> {

    /**
     * 将excel解析的表头转化成对应的map
     * @param map
     * @param originKey
     * @param value
     */
    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        if (value instanceof Double) {
            map.put(getRealKey(originKey), PoiPublicUtil.doubleToString((Double) value));
        } else {
            map.put(getRealKey(originKey), value != null ? value.toString() : null);
        }
    }

    /**
     * 转换excel标题中的字段
     * @param originKey
     * @return
     * @author laoyu
     * @date 2018-07-24
     */
    private String getRealKey(String originKey){

        if (originKey.contains("序号"))
            return "number";
        if (originKey.contains("项目"))
            return "project";
        if (originKey.contains("本期预计收入金额_PISO"))
            return "incomePS";
        if (originKey.contains("A折为RMB"))
            return "incomeRMB";
        if (originKey.contains("本期预计支出金额_PISO"))
            return "expenditurePS";
        if (originKey.contains("B折为RMB"))
            return "expenditureRMB";
        if (originKey.contains("备注"))
            return "remarks";


        return null;
    }
}
